package com.psp.bu.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.bu.model.CooperationBean;
import com.psp.bu.persist.dao.CooperationDao;

@Repository
public class CooperationImpl extends BaseImpl implements CooperationDao {

	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".CooperationMapper";

	@Override
	public int selectCount(int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		if(cateCode != 99) {
			where.put("cateCode", cateCode);
		}
		where.put("content", content);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public List<CooperationBean> selectList(int page, int pageSize, int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		if(cateCode != 99) {
			where.put("cateCode", cateCode);
		}
		where.put("content", content);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int updateHandleState(String cid, int state) {
		Map<String, Object> where = new HashMap<>();
		where.put("state",state);
		where.put("cid", cid);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateHandleState", where);
	}

	@Override
	public CooperationBean selectOneById(String cid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", cid);
	}


}
